package com.baiyue.controller;


import com.baiyue.model.menu.MenuDataRequest;
import com.baiyue.model.menu.MenuTreeDataResponse;
import com.baiyue.model.menu.TreeNodeResponse;
import com.baiyue.result.Result;
import com.baiyue.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * @author 伍波
 * @date 2023-04-17
 */
@RestController
@RequestMapping("/api/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @PostMapping("/add")
    public Result<Boolean> insertMenu(@RequestBody  MenuDataRequest request){
        menuService.insertMenu(request);
        return Result.success(true);
    }

    @PostMapping("/getMenu")
    public Result<List<MenuTreeDataResponse>> getMenuTree(@RequestBody MenuDataRequest request){
        return Result.success(menuService.getMenuTreeByUser(request));
    }

    @PostMapping("/getAllMenu")
    public Result<List<TreeNodeResponse>> getMenuTreeAll(@RequestBody MenuDataRequest request){
        return Result.success(menuService.getAllMenuList(request));
    }
}

